package com.sk.cardeal.adapter;

import android.support.annotation.Nullable;
import android.widget.CheckBox;
import android.widget.CompoundButton;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sk.cardeal.R;
import com.sk.cardeal.act.home.activity.ChooseByPartsActivity;
import com.sk.cardeal.callback.CheckCallback;
import com.sk.cardeal.entity.ByPartsList;

import java.util.List;

/**
 * Created by sk on 2018/3/29.
 */

public class ByPartsListAdapter extends BaseQuickAdapter<ByPartsList.ResultListBean, BaseViewHolder> {

    private CheckCallback checkCallback;

    public ByPartsListAdapter(int layoutResId, @Nullable List<ByPartsList.ResultListBean> data, CheckCallback checkCallback) {
        super(layoutResId, data);
        this.checkCallback = checkCallback;
    }

    @Override
    protected void convert(final BaseViewHolder helper, ByPartsList.ResultListBean item) {
        helper.setText(R.id.parts_name, item.getPartsName())
                .setText(R.id.tv_price, "￥" + item.getPriceQx())
                .setText(R.id.tv_oe, "OE:" + item.getPartsOeCode())
                .setText(R.id.tv_stock, "库存:" + item.getStockNum());

        if (item.isSelect()) {
            helper.setChecked(R.id.checkbox, true);
        } else {
            helper.setChecked(R.id.checkbox, false);
        }

        CheckBox checkBox = helper.getView(R.id.checkbox);
        checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                   checkCallback.check(helper.getAdapterPosition(),true);
                }else{
                    checkCallback.check(helper.getAdapterPosition(),false);
                }
            }
        });
    }

}
